Skip to content

create_dem: make sure the DEM really gets WGS84 ellipsoidal heights - #161

Open
alhandwerger wants to merge 2 commits into
isce-framework:mainfrom
alhandwerger:fix/dem-ellipsoid-heights-need-geoid-grid
Open

alhandwerger wants to merge 2 commits into
isce-framework:mainfrom
alhandwerger:fix/dem-ellipsoid-heights-need-geoid-grid

Conversation

@alhandwerger

Copy link
Copy Markdown

Problem

create_dem relies on sardem to convert Copernicus heights (EGM2008) to WGS84 ellipsoidal heights with a GDAL warp.
When PROJ cannot reach the EGM2008 grid, the warp applies no vertical shift and the DEM silently keeps geoid heights,
off by the local undulation (tens of meters). This is the default in a fresh conda-forge or pixi environment: the
proj package ships no geoid grids, and PROJ network access is off by default.

sweets passes this DEM to radar-geometry steps such as COMPASS geocoding. A geoid-height DEM shifts pixels across
track by roughly dh / tan(look angle) there, with no warning.

Fix

create_dem now wraps the sardem call in a small context manager, _geoid_grid_access. It:

  • enables PROJ network access while the DEM is made (a locally installed grid is used as is);
  • checks that the EGM2008 shift is actually available at the centre of the area, and raises with remediation steps if
    it is not;
  • restores the previous setting.

Network access has to be enabled before the first lookup, because PROJ remembers a grid it failed to find for the
rest of the process.

A companion sardem PR (scottstanie/sardem#31) fixes this at the source. Once that is released, this wrapper can be replaced by a minimum
sardem version.

Tests

tests/test_dem.py runs offline, with the PROJ lookup and sardem mocked:

  • create_dem raises without calling sardem when the shift is unavailable;
  • network access is on while sardem runs and is restored afterwards.

Both tests fail without the fix. The rest of the suite is unchanged locally. One test in test_download_search.py
errors both before and after, from an aiohttp/cassette version mismatch unrelated to this change.

🤖 Generated with Claude Code

alhandwerger and others added 2 commits November 22, 2026 13:21
sardem converts Copernicus heights (EGM2008) to ellipsoidal heights with a GDAL
warp. When PROJ cannot reach the geoid grid (the default with conda-forge proj),
the DEM silently keeps geoid heights, which biases radar-geometry steps such as
COMPASS geocoding by roughly dh / tan(look angle).

Wrap the sardem call in a scoped context that enables PROJ network access,
verifies the EGM2008 shift at the bbox centre and raises otherwise, then
restores the previous setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant